package collision;

import java.util.ArrayList;
import java.util.Random;



public class EnemyWave
{

   
    private int[][] wave;
    
    private int upperLimit, lowerLimit;
    private int lenght;
    private int size;
    private ArrayList<Shootable> enimies;
    
    private final int BOARD_WIDTH = 700;


    /**
     * Enemy wave constructor.
     */
    public EnemyWave() 
    {
    	upperLimit = 300;
    	lowerLimit = 450;
    	lenght = 3500;
    	size = 30;
    	wave = new int[size][2];
    	fillWave();
    }
    

    /**
     * Enemy wave constructor.
     * 
     * @param  low 		lowest height an enemy can appear
     * @param  high 	highest height an enemy can appear
     * @param  l 		the length of the entire wave in pixels
     * @param  s 		the number of enemies in the wave
     */
    public EnemyWave(int low, int high, int l, int s) 
    {
    	upperLimit = high;
    	lowerLimit = low;
    	lenght = l;
    	size = s;
    	wave = new int[size][2];
    	fillWave();
    	//initEnimies();
    }
    
    /**
     * Fills the wave with random positions of enemies
     */
    public void fillWave()
    {
    	Random rand = new Random();
    	for(int i=0; i < size; i++)
    	{
    		int x = rand.nextInt(lenght-BOARD_WIDTH)+BOARD_WIDTH;
    		int y = rand.nextInt(lowerLimit-upperLimit)+upperLimit;
    		
    		wave[i][0]= x;
    		wave[i][1]= y;
    	}
    	
    }

    /**
     * Return wave data.
     * 
     * @return  only the wave data not a wave filled with enemies;
     */
    public int[][] getWave() 
    {
        return wave;
    }
    
    /**
     * Returns the Bird array list.
     * 
     * @return  an array list of Bird all at the correct position and speed.
     */
    public ArrayList<Shootable> getBirds()
    {
    	initBirds();
    	return enimies;
    }
    
    /**
     * Returns the alien array list.
     * 
     * @return  an array list of aliens all at the correct position and speed.
     */
    public ArrayList<Shootable> getAliens()
    {
    	initAliens();
    	return enimies;
    }

    private void initAliens() 
    {
    	
    	Random rand = new Random();
    	enimies = new ArrayList<Shootable>();


        for (int i=0; i<wave.length; i++ ) {
        	int speed = 1;
        	if(rand.nextInt(6)==5)
        		speed=2;
        	enimies.add(new Alien(wave[i][0], wave[i][1], speed));
        }
        
       // System.out.print(aliens.toString());
    }
    
    private void initBirds() 
    {
    	
    	//Random rand = new Random();
    	enimies = new ArrayList<Shootable>();

        for (int i=0; i<wave.length; i++ ) {
        	int speed = 1;
        	enimies.add(new Bird(wave[i][0], wave[i][1], speed));
        }
        
       // System.out.print(aliens.toString());
    }

}
